package guda.stark.biz.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import guda.stark.biz.DepositRuleBiz;
import guda.stark.dal.dao.DepositRuleDAO;
import guda.stark.dal.dataobject.DepositRuleDO;
import guda.grape.autogen.common.page.BaseQuery;
import guda.grape.autogen.common.page.BizResult;

public class DepositRuleBizImpl implements DepositRuleBiz{

    private final static Logger logger = LoggerFactory.getLogger(DepositRuleBizImpl.class);

    @Autowired
    private DepositRuleDAO depositRuleDAO;

    public BizResult detail(long id) {
        BizResult bizResult = new BizResult();
        try{
            DepositRuleDO depositRuleDO = depositRuleDAO.getDepositRuleById(id);
            bizResult.data.put("depositRuleDO", depositRuleDO);
            bizResult.success = true;
        }catch(Exception e){
            logger.error("query DepositRule error",e);
        }
        return bizResult;
}

    public BizResult list(BaseQuery baseQuery) {
        BizResult bizResult = new BizResult();
        try {
            int totalCount = depositRuleDAO.countForPage(baseQuery);
            baseQuery.setTotalCount(totalCount);
            List<DepositRuleDO> depositRuleList = depositRuleDAO.selectForPage(baseQuery);
            bizResult.data.put("depositRuleList", depositRuleList);
            bizResult.data.put("query", baseQuery);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("view DepositRule list error", e);
        }
            return bizResult;
     }

    public BizResult delete(long id) {
        BizResult bizResult = new BizResult();
        try {
            depositRuleDAO.delDepositRuleById(id);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("delete depositRule error", e);
        }
        return bizResult;
    }

    public BizResult create(DepositRuleDO depositRuleDO) {
        BizResult bizResult = new BizResult();
        try {
            long id = depositRuleDAO.insert(depositRuleDO);
            bizResult.data.put("id", id);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("create DepositRule error", e);
        }
        return bizResult;
    }

    @Override
    public BizResult update(DepositRuleDO depositRuleDO) {
        BizResult bizResult = new BizResult();
        try {
            depositRuleDAO.updateByIdSelective(depositRuleDO);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("update DepositRule error", e);
        }
        return bizResult;
    }


}
